package com.atguigu.tingshu.account.account;

import com.atguigu.tingshu.account.service.UserAccountService;
import com.atguigu.tingshu.common.constant.KafkaConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AccountReceiver{

    @Autowired
    private UserAccountService userAccountService;

    //监听消息
    @KafkaListener(topics = KafkaConstant.QUEUE_USER_REGISTER)
    public void receiverUserRegister(ConsumerRecord<String, String> record){
        //  获取用户Id
        Long userId = Long.parseLong(record.value());
        if (null == userId){
            return;
        }
        //  添加账户信息
        userAccountService.addUserAccount(userId);
    }
}
